package com.my.ruyi.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;

import com.my.ruyi.util.HttpClientUtil;

@Component
public class DemoJob implements Job{

	private String httpHost;
	private String httpUrl;
	private String httpType;
	
	// 注入参数
	public void setHttpHost(String httpHost) {
		this.httpHost = httpHost;
	}

	public void setHttpUrl(String httpUrl) {
		this.httpUrl = httpUrl;
	}

	public void setHttpType(String httpType) {
		this.httpType = httpType;
	}
	
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		String url = "";
		if (httpHost.startsWith("http") || httpHost.startsWith("https")
				|| httpHost.equals("null") || httpHost.equals("") ) {
			url = httpUrl;
		}else {
			url = "http://" + httpHost + httpUrl;
		}
		if (httpType.equalsIgnoreCase("get")) {
			HttpClientUtil.httpGetRequest(url);
		} else if (httpType.equalsIgnoreCase("post")) {
			HttpClientUtil.httpPostRequest(url);
		}
	}

}
